﻿using GGGK.Film.IRepository;
using GGGK.Film.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace GGGK.Film.Service
{
    public class BaseService<T> : BaseQueryService,IBaseService<T> where T : class, new()
    {
        private readonly IBaseRepository<T> repository;

        public BaseService(IBaseRepository<T> repository,IBaseQueryRepository baseQuery):base(baseQuery)
        {
            this.repository = repository;
        }

        public bool Add(T t)
        {
            repository.Add(t);

            return repository.SaveChanges();
        }

        public bool Delete(T t)
        {
            repository.Delete(t);
            return repository.SaveChanges();
        }

        public T? Get(Expression<Func<T, bool>> whereLambda)
        {
            return repository.Get(whereLambda);
        }

        public IQueryable<T> Query(Expression<Func<T, bool>> whereLambda)
        {
            return repository.Query(whereLambda);
        }

        public bool SaveChanges()
        {
            return repository.SaveChanges();
        }

        public bool Update(T t)
        {
            repository.Update(t);
            return repository.SaveChanges();
        }
    }
}
